import time

from selenium.webdriver.common.by import By

from common.basePage import Base


class Login(Base):
    # 输入用户名
    def input_username(self, username):
        self.base_send(By.ID, "username", username)

    # 输入密码
    def input_pwd(self, pwd):
        self.base_send(By.ID, "password", pwd)

    # 点击登录
    def login_click(self):
        self.base_click(By.ID, "loginBtn")

    # 清除username、pwd输入框的文本
    def clear_username_pwd(self):
        self.base_send_clear(By.ID, "username")
        self.base_send_clear(By.ID, "password")

    def login(self, username, pwd):
        # username、pwd 为None时，输入空字符串
        if username is None: username = ""
        if pwd is None: pwd = ""
        self.input_username(username)
        self.input_pwd(pwd)
        self.login_click()
        return self


if __name__ == '__main__':
    login = Login()
    login.base_send(By.ID, "username", "byhy")
    print(login.base_get_text(By.ID, "username"))
    login.login_click()